Sketch in Groundspeak GPX fields. With this in place, the icon types
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 16 Oct 2002 05:41:51 +0000 (05:41 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 16 Oct 2002 05:41:51 +0000 (05:41 +0000)
on my magellan now show up differently for virtuals and physicals.

Also, fix problem with magellan serial protocol on windows.

gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/magproto.c

index c3870be73e2c5da4ad43107a8c909f3569f4d71d..7c8484d998847e47dc5323e6d42c652a6c31020c 100644 (file)
@@ -64,6 +64,26 @@ typedef struct {
        altitude altitude;
 } position;
 
+/*
+ * Extended data if waypoint happens to represent a geocache.  This is 
+ * totally voluntary data...
+ */
+
+typedef enum {
+       gt_unknown = 0 ,
+       gt_traditional,
+       gt_multi,
+       gt_virtual,
+       gt_letterbox,
+       gt_event,
+       gt_suprise
+} geocache_type;
+
+typedef struct {
+       geocache_type type;
+       int diff; /* (multiplied by ten internally) */
+       int terr; /* (likewise) */
+} geocache_data ;
 
 /*
  * This is a waypoint, as stored in the GPSR.   It tries to not 
@@ -80,6 +100,7 @@ typedef struct {
        char *url_link_text;
        const char *icon_descr;
        time_t creation_time;
+       geocache_data gc_data;
 } waypoint;
 
 typedef void (*ff_init) (char const *);
@@ -149,3 +170,4 @@ void le_write32(void *pp, unsigned i);
  * but that's not very nice for the folks near sea level.
  */
 #define unknown_alt -99999999.0
+
index 7ef7c96953a00e16c37a6cae16e55104530b5984..4e3b8cf931f5ec2993e49db9b4111798eca96241 100644 (file)
@@ -29,6 +29,9 @@ static int in_name;
 static int in_time;
 static int in_desc;
 static int in_cdata;
+static int in_gs_type;
+static int in_gs_diff;
+static int in_gs_terr;
 static char *cdatastr;
 
 static XML_Parser psr;
@@ -98,12 +101,42 @@ gpx_start(void *data, const char *el, const char **attr)
                tag_wpt(attr);
        } if (strcmp(el, "time") == 0) {
                in_time++;
+       } if (strcmp(el, "groundspeak:type") == 0) {
+               in_gs_type++;
+       } if (strcmp(el, "groundspeak:difficulty") == 0) {
+               in_gs_diff++;
+       } if (strcmp(el, "groundspeak:terrain") == 0) {
+               in_gs_terr++;
        }
 }
 
+struct
+gs_type_mapping{
+       geocache_type type;
+       const char *name;
+} gs_type_map[] = {
+       { gt_traditional, "Traditional cache" },
+       { gt_virtual, "Virtual cache" }
+};
+static
+geocache_type
+gs_mktype(char *t)
+{
+       int i;
+       int sz = sizeof(gs_type_map) / sizeof(gs_type_map[0]);
+
+       for (i = 0; i < sz; i++) {
+               if (0 == strcmp(t, gs_type_map[i].name)) {
+                       return gs_type_map[i].type;
+               }
+       }
+       return gt_unknown;
+}
+
 static void
 gpx_end(void *data, const char *el)
 {
+       float x;
        if (in_cdata) {
                if (in_name && in_wpt) {
                        wpt_tmp->shortname = xstrdup(cdatastr);
@@ -129,6 +162,17 @@ gpx_end(void *data, const char *el)
                        tm.tm_isdst = 1;
                        wpt_tmp->creation_time = mktime(&tm);
                }
+               if (in_wpt && in_gs_type) {
+                       wpt_tmp->gc_data.type = gs_mktype(cdatastr);
+               }
+               if (in_wpt && in_gs_diff) {
+                       sscanf(cdatastr, "%f", &x);
+                       wpt_tmp->gc_data.diff = x * 10;
+               }
+               if (in_wpt && in_gs_terr) {
+                       sscanf(cdatastr, "%f", &x);
+                       wpt_tmp->gc_data.terr = x * 10;
+               }
                in_cdata--;
                memset(cdatastr, 0, MY_CBUF);
        }
@@ -147,6 +191,12 @@ gpx_end(void *data, const char *el)
                in_ele--;
        } else if (strcmp(el, "time") == 0) {
                in_time--;
+       } if (strcmp(el, "groundspeak:type") == 0) {
+               in_gs_type--;
+       } if (strcmp(el, "groundspeak:difficulty") == 0) {
+               in_gs_diff--;
+       } if (strcmp(el, "groundspeak:terrain") == 0) {
+               in_gs_terr--;
        }
 }
 
@@ -160,8 +210,10 @@ gpx_cdata(void *dta, const XML_Char *s, int len)
         * horrible state just I can concatenate buffers that it hands
         * me as a cdata that are fragmented becuae they span a read.  Grrr.
         */
-
        if ((in_name && in_wpt) || (in_desc && in_wpt) || (in_ele) || 
+                       (in_wpt && in_gs_type) || 
+                       (in_wpt && in_gs_diff) || 
+                       (in_wpt && in_gs_terr) || 
                        (in_time && (in_wpt || in_rte)))  {
                estr = cdatastr + strlen(cdatastr);
                memcpy(estr, s, len);
index 60bd44ac443fbf4794cc6bafb98f334819306062..83272a2a2dbdc80863f814ac8940741791c2035e 100644 (file)
@@ -1,4 +1,4 @@
-/*
+       /*
     Communicate Thales/Magellan serial protocol.
 
     Copyright (C) 2002 Robert Lipe, robertlipe@usa.net
@@ -53,7 +53,6 @@ static mag_rxstate magrxstate;
 static int mag_error;
 static int last_rx_csum;
 static int found_done;
-static icon_mapping_t *icon_mapping;
 static int got_version;
 static int is_file = 0;
 
@@ -129,6 +128,8 @@ static icon_mapping_t map330_icon_table[] = {
        { "an", "winery" },
        { "ao", "wreck" },
        { "ap", "zoo" },
+       { "ah", "Virtual cache"},
+       { "an", "Event"},
        { NULL, NULL } 
 };
 
@@ -142,6 +143,7 @@ pid_to_model_t pid_to_model[] =
        { mm_unknown, 0, NULL }
 };
 
+static icon_mapping_t *icon_mapping = map330_icon_table;
 
 
 /*
@@ -375,7 +377,6 @@ if (debug_serial)
                found_done = 1;
                return;
        } 
-
        mag_writeack(isum);
 }
 
@@ -396,7 +397,14 @@ terminit(const char *portname)
                          OPEN_EXISTING, 0, NULL);
 
        if (comport == INVALID_HANDLE_VALUE) {
-               fatal(MYNAME ": '%s'", portname);
+               char *buf;
+
+               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                       FORMAT_MESSAGE_FROM_SYSTEM |
+                       FORMAT_MESSAGE_IGNORE_INSERTS,
+                       NULL,GetLastError(),0,
+                       (LPTSTR) &buf,0,NULL);
+               fatal(MYNAME ": '%s' cannot be opened. %s", portname, buf);
        }
        tio.DCBlength = sizeof(DCB);
        GetCommState (comport, &tio);
@@ -445,12 +453,13 @@ termread(char *ibuf, int size)
 
        ibuf[i]='a';
        for(;i < size;i++) {
-               if (ReadFile (comport, &ibuf[i], 1, &cnt, NULL) != TRUE) 
+               if (ReadFile (comport, &ibuf[i], 1, &cnt, NULL) != TRUE)
                        break;
                if (ibuf[i] == '\n') break;
        }
        ibuf[i] = 0;
        return ibuf;
+
 }
 
 static void
@@ -462,7 +471,6 @@ termwrite(char *obuf, int size)
                fwrite(obuf, size, 1, magfile_out);
                return;
        }
-
        WriteFile (comport, obuf, size, &len, NULL);
        if (len != size) {
                fatal(MYNAME ":.  Wrote %d of %d bytes.", len, size);
@@ -587,6 +595,11 @@ mag_wr_init(const char *portname)
                mag_cleanse = m330_cleanse;
                got_version = 1;
        } else {
+               /*
+                *  This is a serial device.   The line has to be open for
+                *  reading and writing, so we let rd_init do the dirty work.
+                */
+               fclose(magfile_out);
                mag_rd_init(portname);
        }
 }
@@ -799,6 +812,12 @@ mag_waypt_pr(const waypoint *waypointp)
        lat = (lat_deg * 100.0 + lat);
        
        icon_token = mag_find_token_from_descr(waypointp->icon_descr);
+       switch (waypointp->gc_data.type) {
+               case gt_virtual:
+                       icon_token = mag_find_token_from_descr("Virtual cache");
+                       break;
+
+       }
        owpt = global_opts.synthesize_shortnames ?
                         mkshort(waypointp->description) : waypointp->shortname,
        odesc = waypointp->description ? waypointp->description : "";
@@ -830,9 +849,14 @@ mag_write(void)
 {
        if (!is_file) {
                mag_readmsg();
+#if !__WIN32__
+               /*
+                * I have no idea why this is fatal under Windows.
+                */
                mag_readmsg();
                mag_readmsg();
                mag_readmsg();
+#endif
        }
        /* 
         * Whitespace is actually legal, but since waypoint name length is